package com.qingxin.web.action;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.qingxin.park.entity.ParkTeSe;
import com.qingxin.park.service.FarmParkService;
import com.qingxin.park.service.FarmParkTeseService;
import com.qingxin.park.vo.TracePark;
import com.qingxin.sys.action.BaseAction;
import com.qingxin.sys.mvc.PageParam;
import com.qingxin.sys.mvc.Pager;
import com.qingxin.web.service.TraceQueryService;

/**
 * 园区
 * @author Administrator
 *
 */
@Controller
public class ParkAction extends BaseAction {

	@Autowired
	private FarmParkService farmParkService;
	
	@Autowired
	private TraceQueryService traceQueryService;
	
	@Autowired
	private FarmParkTeseService farmParkTeseService;
	
	
	/**
	 * 园区
	 * @param model
	 * @param request
	 * @return
	 */
	@RequestMapping(value="/c/park.do", method=RequestMethod.GET)
	public String park(ModelMap model, HttpServletRequest request) {
		model.put("model", "park");
		return "cms/park";
	}
	
	
	@RequestMapping(value="/c/listPark.json", method={RequestMethod.GET, RequestMethod.POST})
	@ResponseBody
	public Object listPark(PageParam pageParam, HttpServletRequest request){
		pageParam.setPagesize(6);

		Pager pager = farmParkService.listPageTeseParks(pageParam);
		return pager;
	}
	
	
	
	@RequestMapping(value="/c/parkDetail.do", method=RequestMethod.GET)
	public String parkDetail(ModelMap model, String id, HttpServletRequest request){
		model.put("model", "park");
		TracePark park = traceQueryService.getTracePark(id);
		model.put("park", park);
		if(park != null){
			ParkTeSe parkTeSe = farmParkTeseService.getParkTeSe(park.getId(), "1");
			model.put("parkTeSe", parkTeSe);
		}
		
		return "cms/park_detail";
	}
	
	
}
